#include "mainwindow.h"
#include "graphicsPanel.h"
#include "settingwindow.h"
#include <QTextStream>


MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent),
Ui::MainWindow()
{
  setupUi(this);


 QObject::connect(pushButton_QUIT, SIGNAL(clicked(bool) ),
     	    this, SLOT(close() ));
 QObject::connect(pushButton_SETTING, SIGNAL(clicked(bool) ),
     	    this, SLOT(slotSettingPopUp() ));


  gp1 = new GraphicsPanel(graphicsView_1,textBrowser_1,1);
  gp2 = new GraphicsPanel(graphicsView_2,textBrowser_2,2);
  gp3 = new GraphicsPanel(graphicsView_3,textBrowser_3,3);
  gp4 = new GraphicsPanel(graphicsView_4,textBrowser_4,4);
  gp5 = new GraphicsPanel(graphicsView_5,textBrowser_5,5);
  gp6 = new GraphicsPanel(graphicsView_6,textBrowser_6,6);
  gp7 = new GraphicsPanel(graphicsView_7,textBrowser_7,7);
  gp8 = new GraphicsPanel(graphicsView_8,textBrowser_8,8);

  gp1->setSpinBox (spinBox_11,spinBox_12,spinBox_13,spinBox_14);
  gp2->setSpinBox (spinBox_21,spinBox_22,spinBox_23,spinBox_24); 
  gp3->setSpinBox (spinBox_31,spinBox_32,spinBox_33,spinBox_34); 
  gp4->setSpinBox (spinBox_41,spinBox_42,spinBox_43,spinBox_44); 
  gp5->setSpinBox (spinBox_51,spinBox_52,spinBox_53,spinBox_54); 
  gp6->setSpinBox (spinBox_61,spinBox_62,spinBox_63,spinBox_64); 
  gp7->setSpinBox (spinBox_71,spinBox_72,spinBox_73,spinBox_74); 
  gp8->setSpinBox (spinBox_81,spinBox_82,spinBox_83,spinBox_84); 
	
  gp1->setButton (pushButton_1A,pushButton_1B,pushButton_1C);
  gp2->setButton (pushButton_2A,pushButton_2B,pushButton_2C);
  gp3->setButton (pushButton_3A,pushButton_3B,pushButton_3C);
  gp4->setButton (pushButton_4A,pushButton_4B,pushButton_4C);
  gp5->setButton (pushButton_5A,pushButton_5B,pushButton_5C);
  gp6->setButton (pushButton_6A,pushButton_6B,pushButton_6C);
  gp7->setButton (pushButton_7A,pushButton_7B,pushButton_7C);
  gp8->setButton (pushButton_8A,pushButton_8B,pushButton_8C);
	
/*	
  gp1->setAlign (Qt::AlignLeft | Qt::AlignBottom);
  gp2->setAlign (Qt::AlignLeft | Qt::AlignBottom);
  gp3->setAlign (Qt::AlignLeft | Qt::AlignTop);
  gp4->setAlign (Qt::AlignLeft | Qt::AlignTop);
  gp5->setAlign (Qt::AlignLeft | Qt::AlignBottom);
  gp6->setAlign (Qt::AlignLeft | Qt::AlignBottom);
  gp7->setAlign (Qt::AlignLeft | Qt::AlignTop);
  gp8->setAlign (Qt::AlignLeft | Qt::AlignTop);
*/	
/*
The horizontal flags are: 
Qt::AlignLeft    0x0001
Qt::AlignRight   0x0002
Qt::AlignHCenter 0x0004
Qt::AlignJustify 0x0008

The vertical flags are: 
Qt::AlignTop     0x0020
Qt::AlignBottom  0x0040
Qt::AlignVCenter 0x0080
*/
/*
  gp1->setAlign (Qt::AlignLeft | Qt::AlignBottom);
  gp2->setAlign (Qt::AlignLeft | Qt::AlignBottom);
  gp3->setAlign (Qt::AlignRight | Qt::AlignTop);
  gp4->setAlign (Qt::AlignRight | Qt::AlignTop);
	
  gp5->setAlign (Qt::AlignLeft | Qt::AlignBottom);
  gp6->setAlign (Qt::AlignLeft | Qt::AlignTop);
  gp7->setAlign (Qt::AlignRight | Qt::AlignBottom);
  gp8->setAlign (Qt::AlignRight | Qt::AlignTop);
	

  gp1->setScene(0,0,50,100);
  gp2->setScene(50,50,50,100);
  gp3->setScene(0,0,50,100);
  gp4->setScene(50,50,50,100);

  gp5->setScene(0,0,502,500);
  gp6->setScene(0,0,502,500);
  gp7->setScene(0,0,502,500);
  gp8->setScene(0,0,502,500);


  gp1->draw(100);
  gp2->draw(100);
  gp3->draw(100);
  gp4->draw(100);
	
  gp5->draw(500);
  gp6->draw(800);
  gp7->draw(500);
  gp8->draw(500);
*/
 
//
  /*
  
  QPen pen1;
  pen1.setStyle(Qt::SolidLine);
  pen1.setWidth(1);
  pen1.setBrush(Qt::green);

 // graphicsScene->invalidate(x,y,w,h,QGraphicsScene::ItemLayer);
  QGraphicsScene *s  = new QGraphicsScene(0,0,200,200);
  s->invalidate(0,0,200,200,QGraphicsScene::BackgroundLayer);
  s->addLine(0,0,200,200,pen1);
  graphicsView_1->setScene( s);
  graphicsView_1->show();

*/

}

void MainWindow::slotSettingPopUp()
{
	setting = new SettingWindow(this);
	setting->show();


}

GraphicsPanel* MainWindow::getGraphicsPanel( int panelno)
{

 switch (panelno)
 {
	 case 1:  return gp1;
	 case 2:  return gp2;
	 case 3:  return gp3;
	 case 4:  return gp4;
	 case 5:  return gp5;
	 case 6:  return gp6;
	 case 7:  return gp7;
	 case 8:  return gp8;
 default: return gp1;

 };

}


